package com.example.main;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BlueToothValueReceiver extends BroadcastReceiver {

    private static final String TAG = "BlueToothValueReceiver";

    public static int DEFAULT_VALUE_BULUETOOTH = 1000;

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
            int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, DEFAULT_VALUE_BULUETOOTH);
            switch (state) {
                case BluetoothAdapter.STATE_OFF:
                    Log.i(TAG, "onReceive: 蓝牙已关闭");
                    break;
                case BluetoothAdapter.STATE_ON:
                    Log.i(TAG, "onReceive: 蓝牙已打开");
                    break;
                case BluetoothAdapter.STATE_TURNING_ON:
                    Log.i(TAG, "onReceive: 正在打开蓝牙");
                    break;
                case BluetoothAdapter.STATE_TURNING_OFF:
                    Log.i(TAG, "onReceive: 正在关闭蓝牙");
                    break;
                default:
                    Log.i(TAG, "onReceive: 未知状态");
            }
        }
    }
}
